#!/usr/bin/python3
# -*- coding: utf-8 -*-

from flask import current_app
from ..utils.api_response import ApiResponse
import redis

class ServiceController:
    """服务控制器，处理系统服务相关接口"""
    
    @staticmethod
    def redis_test():
        """测试Redis连接的简单接口"""
        try:
            # 获取Redis客户端
            redis_client = redis.Redis(
                host=current_app.config.get('REDIS_HOST', '127.0.0.1'),
                port=current_app.config.get('REDIS_PORT', 6379),
                password=current_app.config.get('REDIS_PASSWORD', ''),
                decode_responses=True
            )
            
            # 设置一个测试值
            redis_client.set('test_key', 'Hello from Flask')
            
            # 获取值
            value = redis_client.get('test_key')
            
            return ApiResponse.success({
                "message": "Redis连接正常",
                "test_value": value
            })
        except Exception as e:
            return ApiResponse.error(f"Redis连接错误: {str(e)}", 500) 